﻿using System;
using System.Web.Mvc;
using Blazing.BusinessObjects.Cms;
using Blazing.WebFacade.Extensions;
using Blazing.MvcBlog.Classes;
using Blazing.WebFacade;

namespace Blazing.MvcBlog.Controllers
{
    public class PostController : BaseController
    {
        private const string STR_TITLE = "Title";

        public ActionResult View()
        {
            PostViewData viewData = new PostViewData();
            viewData.Post = Request.Url.GetCurrentPage();

            ViewData[STR_TITLE] = viewData.Post.Name;

            return View(viewData);
        }

        public ActionResult AddFeedback(string txtTitle, string txtContent, string txtName, 
            string txtEmail, string txtUrl)
        {
            Uri thispage = Request.Url;
            UriBuilder bld = new UriBuilder(Request.Url);
            bld.Path = bld.Path.Replace("/AddFeedback", "/");

            Contentpage page = bld.Uri.GetCurrentPage();
            FeedbackItem item = new FeedbackItem();
            item.Name = txtTitle;
            item.UserName = txtName;
            item.Content = txtContent;
            item.UserEmail = txtEmail;
            item.UserUrl = txtUrl;
            PageController pageController = new PageController();
            pageController.InsertPageFeedback(page, item);


            return Redirect(page.Url);
        }
    }
}
